home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / CTRACE2_ / CTESTAPP.C < prev    next >
C/C++ Source or Header  |  1990-12-10  |  2KB  |  84 lines

  1. /*****     
  2.     Driver program for CTRACE: A MESSAGE LOGGING CLASS
  3.     by William D. Cramer in Dr. Dobbs Journal #170, p. 44-55, 116-120.
  4. *****/
  5.  
  6. /** CTestApp.c -- Demonstrates how to include the CTrace utility as part of your
  7. ** application. Functions it performs are showing/hiding the trace log window
  8. ** and setting the trace mask. To demonstrate the calls to Trace(), 
  9. ** it uses the New and Open menu commands. **/
  10.  
  11. #include <CApplication.h>        /* Application class definitions */
  12. #include <CBartender.h>         /* Bartender class definitions */
  13. #include <Commands.h>            /* standard command definitions */
  14. #include "CTrace.h"                /* Trace log class definitions */
  15.  
  16. /* external references */
  17. extern CBartender     *gBartender;
  18. extern CTrace         *gTrace;
  19.  
  20. /* Declare the application class */
  21. struct CTestApp : CApplication
  22. {
  23.     CTrace    *itsTraceLog;
  24.     void    ITestApp (void);
  25.     void    DoCommand(long c);
  26.     void    UpdateMenus(void);
  27. };
  28.     
  29. /** ITestApp -- Initializes the application and the CTrace object. **/
  30. void CTestApp::ITestApp(void)
  31. {
  32.     CApplication::IApplication (4, 20480L, 2048L);
  33.     itsTraceLog = new (CTrace);
  34.     itsTraceLog->ITrace (100);
  35. }
  36.  
  37. /** UpdateMenus -- Updates the Trace portion of the menus. **/
  38. void CTestApp::UpdateMenus (void)
  39. {
  40.     inherited::UpdateMenus ();
  41.     gBartender->EnableMenu (TRACE_MENU_ID);
  42.     gBartender->EnableCmd (TRACE_MENU_SHOW);
  43.     gBartender->EnableCmd (TRACE_MENU_MASK);
  44.     if (itsTraceLog->IsItVisible ())
  45.         gBartender->CheckMarkCmd (TRACE_MENU_SHOW, TRUE);
  46.     else
  47.         gBartender->CheckMarkCmd (TRACE_MENU_SHOW, FALSE);
  48. }
  49.  
  50. /** DoCommand -- Processes application commands. **/
  51. void CTestApp::DoCommand (long command)
  52. {
  53.     int         i;            /* a loop counter */
  54.     static int addno=1;        /* a counter for the demo adds */
  55.     switch (command)
  56.     {
  57.         case cmdNew :        /* trace one value at mask TRACE_INFO */
  58.             gTrace->Trace (T_INFO, "one'sies add, data=%d", addno++);
  59.             break;
  60.         case cmdOpen :        /* trace 32 messages, one at each mask value */
  61.           for (i=0; i<32; i++)
  62.             gTrace->Trace ((1L<<i), "Entry #%d, trace mask #%d (mask=0x%08lX)",addno++, i+1, (long)(1L<<i));
  63.           break;
  64.         case TRACE_MENU_SHOW :
  65.             itsTraceLog->ToggleTraceWindow ();
  66.             break;
  67.         case TRACE_MENU_MASK :
  68.             itsTraceLog->SetTraceMask ();
  69.             break;
  70.         default :
  71.             inherited::DoCommand (command);
  72.     }
  73. }
  74.  
  75. /** main() -- Main routine of the demo program. **/
  76. void main ()
  77. {
  78.     gApplication = new (CTestApp);
  79.     ((CTestApp*)gApplication)->ITestApp ();
  80.     gApplication->Run ();
  81.     gApplication->Exit ();
  82. }
  83.  
  84.